package com.sth.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sth.edu.entity.Teacher;
import com.sth.edu.mapper.TeacherMapper;
import com.sth.edu.service.TeacherService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author sth
 * @since 2020-11-29
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    //1. 分页查询将讲师的方法
    @Override
    public Map<String, Object> getTeacherFrontList(Page<Teacher> pageTecher) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        baseMapper.selectPage(pageTecher,queryWrapper);

        List<Teacher> records = pageTecher.getRecords();
        long current = pageTecher.getCurrent();
        long pages = pageTecher.getPages();
        long size = pageTecher.getSize();
        long total = pageTecher.getTotal();
        boolean hasNext = pageTecher.hasNext();
        boolean hasPrevious = pageTecher.hasPrevious();

        // 把分页数据取出来,放入map
        Map<String,Object> map=new HashMap<>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}
